package com.hc.lookSys.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hc.lookSys.pojo.UserInfo;
import com.hc.lookSys.services.UserInfoServices;
import com.hc.lookSys.services.UserInfoServicesImpl;

public class UsersLoginServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -941197689549699564L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");

		String loginAccount = request.getParameter("loginAccount");// 获取到账号的数据
		String loginPwd = request.getParameter("loginPwd");// 获取密码的数据

		System.out.println("账号： " + loginAccount + ",密码：" + loginPwd);

		UserInfoServices userInfoBiz = new UserInfoServicesImpl();
		// 创建对象
		UserInfo userInfo = userInfoBiz.findUserLogin(loginAccount, loginPwd);

		if (null != userInfo) {
			request.getSession().setAttribute("userInfo", userInfo);
			response.sendRedirect("findInfoAllAcction");
		//	response.sendRedirect("跳转页面");
		} else {
			request.setAttribute("errorMsg", "账号或者密码错误!请重新输入@@@");
			request.getRequestDispatcher("login.jsp").forward(request, response);// 页面转发
			// request.getRequestDispatcher("转发的页面").forward(request,
			// response);//页面转发,表示转发到某个页面
		}
	}

}
